/**
 * @作者 伟子涵
 * @微信公号 搬砖暗夜码农
 * @开源项目 $ https://gitee.com/zhouwei5208888
 * @我的博客 $ http://itzhouwei.com
 * @创建时间 2023/11/30 19:27
 */
package com.itzhouwei.mybatis.session.defaults;

import com.itzhouwei.mybatis.binding.MapperRegistry;
import com.itzhouwei.mybatis.session.SqlSession;

/**
 * @description: SqlSession 的默认实现
 * @author：zw，微信：yingshengzw
 * @date: 2023/11/30 19:27
 * @Copyright： 公众号：搬砖暗夜码农 | 博客：https://itzhouwei.com - 沉淀、分享、成长，让自己和他人都能有所收获！
 */
@SuppressWarnings("all")
public class DefaultSqlSession implements SqlSession {

    /***
     * <h1>映射器注册机</h1>
     */
    private MapperRegistry mapperRegistry;

    /***
     * @param sqlSession
     * @param mapperRegistry
     */
    DefaultSqlSession(MapperRegistry mapperRegistry) {
        this.mapperRegistry = mapperRegistry;
    }



    @Override
    public <T> T selectOne(String statement) {
        return (T) ("你被代理了"+statement);
    }


    @Override
    public <T> T selectOne(String statement, Object parameter) {
        return (T) ("你被代理了！" + "方法：" + statement + " 入参：" + parameter);
    }

    /***
     * 获取映射器
     * @param type
     * @param sqlSession
     * @return
     * @param <T>
     */
    @Override
    public <T> T getMapper(Class<T> type) {
        return mapperRegistry.getMapper(type,this);
    }
}
